﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CoreEx.DynamicInvoker.Tests
{
    public class TestClass
    {
        private int _valueType = 10;
        private static int _staticValueType = 10;

        private object _boxedValueType = 10;

        private StringBuilder _referenceTypeField = new StringBuilder("SomeValue");

        private List<object> _invokeResult
            = new List<object>();


        private void SaveResult(params object[] values)
        {
            _invokeResult.AddRange(values);
        }

        public StringBuilder InstanceMethodReturnsReferenceType()
        {
            StringBuilder sb = new StringBuilder("SomeValue");
            return sb;
        }

        public StringBuilder ReferenceTypeProperty
        {
            get { return _referenceTypeField; }
            set { _referenceTypeField = value; }
        }
            
        public int InstanceValueTypeProperty
        {
            get
            {
                return _valueType;
            }
            set
            {
                _valueType = value;                
            }
        }

        public static int StaticValueTypeProperty { get; set; }


        public List<object>InvokeResult
        {
            get { return _invokeResult; }
        }

        public void InstanceMethod()
        {
            SaveResult("InstanceMethod");
        }

        public void InstanceByRefMethod(ref string value)
        {
            value = "SomeOtherValue";
        }

        public string StaticMethod()
        {
            return "StaticMethod";
        }


        public void ValueType(int value)
        {
            SaveResult(value);
        }

        public void ReferenceType(StringBuilder value)
        {
            value.Append("SomeValue");
            SaveResult(value);
        }

        public static int StaticValueType(int value)
        {
            return value*10;
        }

        public static StringBuilder StaticReferenceType(StringBuilder value)
        {
            value.Append("SomeValue");
            return value;
        }



        public void OverLoadedMethod(int value1)
        {
            SaveResult(value1);
        }

        public void OverLoadedMethod(int value1, int value2)
        {
            SaveResult(value1,value2);
        }


        public void OverLoadedByParameterType(string value)
        {
            SaveResult(value);
        }

        public void OverLoadedByParameterType(int value)
        {
            SaveResult(value);
        }


        public void ErrorMethod()
        {
            int divisor  = 0;

            var result = 10/divisor;
        }


        public byte ByteProperty { get; set; }


        public void TestMethod(object testStruct, int value)
        {
            TestStruct local = (TestStruct) testStruct;
            local.InstanceValueTypeMethod(value);
            testStruct = local;
        }
    }
}
